package com.gombe.credit.app.ui.dialog

import android.content.Context
import android.view.LayoutInflater
import android.view.View
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import com.gombe.credit.app.common.CommonDialog
import com.gombe.credit.app.databinding.DialogGombeCreditStepWalletSubmitCompleteBinding
import com.gombe.credit.app.event.GombeCreditEventPointType
import com.gombe.credit.app.ui.adapter.AdapterGombeCreditStepWalletComplete
import com.gombe.credit.app.utils.GombeCreditDensityUtil
import com.gombe.credit.app.utils.decoration.LinearSpacingItemDecoration
import com.gombe.credit.lib.adapter.GombeCreditOnItemChildClickListener
import org.json.JSONObject

/**
 * GombeCredit
 * @Author wwdeng
 * @CreateTime: 2024/11/21 13:45
 * @Annotation：绑卡确认dialog
 */
class DialogGombeCreditWalletComplete: CommonDialog {
    private lateinit var binding: DialogGombeCreditStepWalletSubmitCompleteBinding
    private var mCallback: IDialogCallback? = null

    private var itemAdapter: AdapterGombeCreditStepWalletComplete? = null

    constructor(context: Context) : super(context) {}
    constructor(context: Context, callback: IDialogCallback?) : super(context) {
        mCallback = callback
    }

    /**
     * 设置点击回调
     */
    fun setOnClick(callback: IDialogCallback){
        this.mCallback = callback
    }

    override fun takeGombeCreditRootView(): View {
        binding = DialogGombeCreditStepWalletSubmitCompleteBinding.inflate(LayoutInflater.from(context))
        return binding.root
    }

    override fun initGombeCreditView() {
        initGombeCreditWalletCompleteListView()
    }

    override fun initGombeCreditListener() {
        setOnClickListener(binding.buttonWalletAccountConfirm)
        setOnClickListener(binding.imageWalletAccountSubmitCompleteClose)//关闭
    }

    override fun takeGombeCreditData() {
    }

    override fun onGombeCreditViewClick(v: View?) {
        dismiss()
        if(mCallback != null){
            mCallback?.onClick(v)
        }
    }

    /**
     * 初始化账户列表
     */
    private fun initGombeCreditWalletCompleteListView() {
        val topDecoration = GombeCreditDensityUtil.dp2px(12f)
        binding.walletAccountListView.addItemDecoration(LinearSpacingItemDecoration(0, 0, topDecoration, topDecoration))
        binding.walletAccountListView.layoutManager = LinearLayoutManager(context)
        itemAdapter = AdapterGombeCreditStepWalletComplete(binding.walletAccountListView)
        binding.walletAccountListView.adapter = itemAdapter
        binding.walletAccountListView.itemAnimator = DefaultItemAnimator()
        itemAdapter?.setOnItemChildClickListener(GombeCreditOnItemChildClickListener { _, childView, position ->
        })
    }

    /**
     * 设置账户列表
     */
    fun showGombeCreditCompleteWalletList(accountList: MutableList<JSONObject>){
        itemAdapter?.data = accountList
    }

    interface IDialogCallback {
        //按钮点击
        fun onClick(view: View?)
    }

    override fun onStart() {
        super.onStart()
        addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_DIALOG.USER_WALLET_SUBMIT_CONFIRM_TIPS_SHOW)
    }

    override fun dismiss() {
        super.dismiss()
        addEventPointRequestAction(GombeCreditEventPointType.GOMBECREDIT_TRACK_DIALOG.USER_WALLET_SUBMIT_CONFIRM_TIPS_DISMISS)
    }
}